// pages/branchInfo/branchInfo.js
var util = require("../../utils/util.js")
var urlApi = require("../../utils/server.api.js")
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: "",
    isYGWXChecked: true,
    isXCGChecked: true,
    isCTChecked: true,
    isXGChecked: true,
    totalObj: [],
    title: "请选择需要查询的报告：",
    totalPrice: 0,
    dayLog: [],
    sickName: "",
    sickCard: "",
    show: "hidden",
    type: "",
    checkItemIds: []
  },

  report: function () {
    if (this.data.isYGWXChecked) {
      this.data.checkItemIds.push(1)
    } else {
      this.data.checkItemIds = this.data.checkItemIds.filter((item) => {
        return item !== 1;
      })
    }
    if (this.data.isXCGChecked) {
      this.data.checkItemIds.push(2)
    } else {
      this.data.checkItemIds = this.data.checkItemIds.filter((item) => {
        return item !== 2;
      })
    }
    if (this.data.isCTChecked) {
      this.data.checkItemIds.push(3)
    } else {
      this.data.checkItemIds = this.data.checkItemIds.filter((item) => {
        return item !== 3;
      })
    }
    if (this.data.isXGChecked) {
      this.data.checkItemIds.push(4)
    } else {
      this.data.checkItemIds = this.data.checkItemIds.filter((item) => {
        return item !== 4;
      })
    }
    var that = this;
    console.log(that.data.checkItemIds),
    wx.request({
      url: urlApi.getReportUrl(),
      method: "post",
      header: {
        'content-type': 'application/json'
      },
      data: {
        patientName: app.globalData.userInfo.name,
        checkItemIds: that.data.checkItemIds
      },
      success: function (res) {
        var data = res.data.data;
        var arr = new Array();
        if (res.data.data != "") {
          for (var i of data) {
              i.date = util.format(i.updateTime);
              arr.push(i)
          }
          console.log(arr)
          that.setData({
            pensorShowTop: "hidden",
            pensorShowBottom: "show",
            show: "hidden",
            dayLog: arr
          })
        }else{
          that.setData({
            show: "show",
          })
        }
      }
    })
  },

  detailFun: function(e) {
    console.log(e.currentTarget.dataset.img)
    wx.navigateTo({
      url: '../reportDetail/reportDetail?img=' + e.currentTarget.dataset.img,
    })
  },

  YGWXChange: function() {
    this.setData({
      isYGWXChecked: !this.data.isYGWXChecked
    })
  },

  XCGChange: function() {
    this.setData({
      isXCGChecked: !this.data.isXCGChecked
    })
  },

  CTChange: function() {
    this.setData({
      isCTChecked: !this.data.isCTChecked
    })
  },

  XGChange: function() {
    this.setData({
      isXGChecked: !this.data.isXGChecked
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.report();
    this.setData({
      sickName: app.globalData.userInfo.name,
      sickCard: app.globalData.userInfo.idCard,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})